import 'package:flutter/material.dart';
import 'package:graduation_project/bookrack/bookrack_leader.dart';
import 'package:graduation_project/common/global.dart';

import 'package:graduation_project/found/found_body.dart';
import 'package:graduation_project/leader/leader_menu.dart';
import 'package:graduation_project/menu_bar/search/search_bar.dart';
import 'package:graduation_project/myMessage/myMessage.dart';
import 'bottom_bar/bottom_bar.dart';
import 'bottom_bar/tabIcon_data.dart';

class menu_bar extends StatefulWidget {
  @override
  _menu_barState createState() => _menu_barState();
}

class _menu_barState extends State<menu_bar> {
  final List<TabIconData> tabIconsList = TabIconData.tabIconsList;
  // int pageIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      extendBodyBehindAppBar: true,
      appBar: rAppbar(),
      body: Stack(
        children: [
          content(),
          bottomBar(),
        ],
      ),
    );
  }

  Widget content() {
    return Positioned.fill(
      child: Container(
        alignment: Alignment.center,
        child: menu_page(),
      ),
    );
  }

  Widget bottomBar() {
    return Positioned(
      left: 0,
      right: 0,
      bottom: 0,
      child: Bottom_Bar(
        tabIconsList: tabIconsList,
        changeIndex: (index) => onClickBottomBar(index),
      ),
    );
  }

  void onClickBottomBar(int index) {
    setState(() => pageIndex = index);
  }

  // ignore: non_constant_identifier_names
  Widget menu_page() {
    switch (pageIndex.toString()) {
      case '0':
        return leader_menu();
      case '1':
        return found_body();
      case '2':
        return bookrack_leader();
      case '3':
        return myMessage();
      default:
        return Container(
          alignment: Alignment.center,
          child: Text(pageIndex.toString(),
              style: TextStyle(color: Colors.grey[400], fontSize: 80)),
        );
    }
  }

  // ignore: missing_return
  AppBar rAppbar() {
    switch (pageIndex.toString()) {
      case '0':
        return null;
      case '1':
        return AppBar(
          backgroundColor: Color.fromRGBO(255, 250, 250, 1),
          elevation: 0,
          flexibleSpace: Row(children: [
            Container(

                // width: MediaQuery.of(context).size.width,
                width: 330,
                margin: EdgeInsets.only(top: 40, left: 8, right: 0),
                padding: EdgeInsets.all(4),
                decoration: new BoxDecoration(
                  color: Colors.black12,
                  // 设置四周圆角，角度
                  borderRadius: BorderRadius.all(Radius.circular(10.0)),
                ),
                child: InkWell(
                  onTap: () => {
                    // 跳转到搜索页面
                    // print('111'),
                    // print(appbar0_opacity),

                    Navigator.push(context, MaterialPageRoute(builder: (_) {
                      return search_bar();
                    })),
                  },
                  child: Row(
                    children: [
                      Container(
                        margin: EdgeInsets.all(4),
                        child: Icon(
                          Icons.search,
                          color: Colors.black38,
                          size: 15,
                        ),
                      ),
                      Text('默认样式',
                          style:
                              TextStyle(color: Colors.black38, fontSize: 12)),
                    ],
                  ),
                )),

            // Opacity(opacity: appbar0_opacity)
          ]),
        );
      case '2':
        return null;
      case '3':
        return null;
      default:
        return AppBar(
          backgroundColor: Colors.transparent,
          // backgroundColor: Color(0x44000000),
          elevation: 0,
          title: Text("Title"),
        );
    }
  }
}
